package com.moyq5.mvc.maker.test.bean.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PrePersist;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;

/**
 * GPS记录
 * @author Moyq5
 * @date 2018年4月14日
 */
@Entity
@Table(name = "iot_gps")
@DynamicUpdate
public class IotGps implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2501889911734905845L;
	/**
	 * GpsID
	 */
	@Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "native")@GenericGenerator(name = "native", strategy = "native")
    @Column(name = "gps_id")
	private Long gpsId;
	/**
     * 序列号
     */
    @Column(name = "gps_no", nullable = false, length = 32)
    private String gpsNo;
	/**
	 * 设备
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "device_id")
	private IotDevice device;
	/**
	 * 告警
	 */
	@ManyToOne(fetch = FetchType.LAZY, optional = true)
	@JoinColumn(name = "alarm_id")
	private IotAlarm alarm;
	/**
     * 纬度
     */
    @Column(name = "lat", nullable = false, precision = 10, scale = 6)
    private Float lat;
    /**
     * 经度
     */
    @Column(name = "lng", nullable = false, precision = 10, scale = 6)
    private Float lng;
    /**
     * 速度(km/h)
     */
    @Column(name = "speed", nullable = false, precision = 4, scale = 0)
    private Integer speed;
    /**
     * 航向，范围：0~360（正北为0，顺时针值）
     */
    @Column(name = "course", nullable = false, precision = 4, scale = 0)
    private Integer course;
    /**
	 * GPS时间
	 */
	@Column(name = "gps_time", nullable = false, columnDefinition="datetime")
	private Date gpsTime;
	/**
	 * 添加时间
	 */
	@Column(name = "add_time", nullable = false, columnDefinition="datetime")
	private Date addTime;
	
	@PrePersist
	public void prePersist() {
		if (null == addTime) {
			addTime = new Date();
		}
	}
	
	public Long getGpsId() {
		return gpsId;
	}
	public void setGpsId(Long gpsId) {
		this.gpsId = gpsId;
	}
	public IotDevice getDevice() {
		return device;
	}
	public void setDevice(IotDevice device) {
		this.device = device;
	}
	public Float getLat() {
		return lat;
	}
	public void setLat(Float lat) {
		this.lat = lat;
	}
	public Float getLng() {
		return lng;
	}
	public void setLng(Float lng) {
		this.lng = lng;
	}
	public Integer getSpeed() {
		return speed;
	}
	public void setSpeed(Integer speed) {
		this.speed = speed;
	}
	public Integer getCourse() {
		return course;
	}
	public void setCourse(Integer course) {
		this.course = course;
	}
	public Date getGpsTime() {
		return gpsTime;
	}
	public void setGpsTime(Date gpsTime) {
		this.gpsTime = gpsTime;
	}
	public String getGpsNo() {
		return gpsNo;
	}
	public void setGpsNo(String gpsNo) {
		this.gpsNo = gpsNo;
	}
	public Date getAddTime() {
		return addTime;
	}
	public void setAddTime(Date addTime) {
		this.addTime = addTime;
	}

	public IotAlarm getAlarm() {
		return alarm;
	}

	public void setAlarm(IotAlarm alarm) {
		this.alarm = alarm;
	}
	
}
